﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace HiTeachers.Web
{
    public enum MessageType
    {
        Error = 0,
        Warning = 1,
        Information = 2,
        Success = 3
    }

    public static class InformMessage
    {
        public static void DisplayMessage(this Page page, Label lblMsg, string msg, MessageType msgType)
        {
            switch (msgType)
            {
                case MessageType.Error:
                    {
                        lblMsg.Text = msg;
                        lblMsg.CssClass = "ErrorMsg";
                        break; ;
                    }
                case MessageType.Warning:
                    {
                        lblMsg.Text = msg;
                        lblMsg.CssClass = "WarnMsg";
                        break; ;
                    }
                case MessageType.Information:
                    {
                        lblMsg.Text = msg;
                        lblMsg.CssClass = "InfoMsg";
                        break; ;
                    }
                case MessageType.Success:
                    {
                        lblMsg.Text = msg;
                        lblMsg.CssClass = "SuccMsg";
                        break; ;
                    }
            }
            lblMsg.Visible = true;
            if (page != null) SetMessageTimeOut(page, lblMsg.ClientID);
        }

        public static void CloseMessage(this Page page, Label lblMsg)
        {
            lblMsg.Visible = false;
        }

        private static void SetMessageTimeOut(Page page, string clientId)
        {
            //var strScript = "setTimeout(\"HideAlertMessage('" + clientId + "')\",5000);";
            //ScriptManager.RegisterStartupScript(page, page.GetType(), Guid.NewGuid().ToString(), strScript, true);
        }
    }
}
